<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>MyBatis UnpooledDataSource 深度解析</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .card-hover {
            transition: all 0.3s ease;
            border: 1px solid transparent;
        }
        
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
            border-color: #667eea;
        }
        
        .text-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        
        .code-block {
            background: #1e1e1e;
            border-radius: 12px;
            overflow: hidden;
            position: relative;
        }
        
        .code-header {
            background: #2d2d2d;
            padding: 10px 20px;
            font-size: 12px;
            color: #888;
            display: flex;
            align-items: center;
            justify-content: space-between;
        }
        
        .code-dots {
            display: flex;
            gap: 6px;
        }
        
        .dot {
            width: 12px;
            height: 12px;
            border-radius: 50%;
        }
        
        .dot-red { background: #ff5f56; }
        .dot-yellow { background: #ffbd2e; }
        .dot-green { background: #27c93f; }
        
        pre {
            margin: 0;
            padding: 20px;
            overflow-x: auto;
            color: #e6e6e6;
            font-family: 'Consolas', 'Monaco', monospace;
            font-size: 14px;
            line-height: 1.6;
        }
        
        .feature-icon {
            width: 60px;
            height: 60px;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 16px;
            font-size: 24px;
            margin-bottom: 20px;
        }
        
        .icon-purple {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
        }
        
        .icon-blue {
            background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
            color: white;
        }
        
        .icon-orange {
            background: linear-gradient(135deg, #fa709a 0%, #fee140 100%);
            color: white;
        }
        
        .section-title {
            position: relative;
            padding-left: 20px;
            margin-bottom: 30px;
        }
        
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 30px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 2px;
        }
        
        .highlight-box {
            background: linear-gradient(135deg, #f5f7fa 0%, #e9ecef 100%);
            border-left: 4px solid #667eea;
            padding: 20px;
            border-radius: 8px;
            margin: 20px 0;
        }
        
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 30px 0;
        }
        
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        .animate-fadeInUp {
            animation: fadeInUp 0.8s ease-out;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20">
        <div class="container mx-auto px-6">
            <div class="max-w-4xl mx-auto text-center animate-fadeInUp">
                <h1 class="text-5xl font-bold mb-6">MyBatis UnpooledDataSource</h1>
                <p class="text-xl opacity-90 mb-8">深入理解 MyBatis 自带的非池化数据源实现</p>
                <div class="flex justify-center gap-4">
                    <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full text-sm">
                        <i class="fas fa-database mr-2"></i>数据源管理
                    </span>
                    <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full text-sm">
                        <i class="fas fa-code mr-2"></i>源码解析
                    </span>
                    <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full text-sm">
                        <i class="fas fa-chart-line mr-2"></i>性能分析
                    </span>
                </div>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="container mx-auto px-6 py-12">
        <div class="max-w-5xl mx-auto">
            
            <!-- Introduction -->
            <div class="bg-white rounded-2xl shadow-xl p-8 mb-8 card-hover">
                <div class="highlight-box">
                    <p class="text-gray-700 leading-relaxed">
                        MyBatis 自带的连接池是 <code class="bg-purple-100 text-purple-800 px-2 py-1 rounded">org.apache.ibatis.datasource.unpooled.UnpooledDataSource</code>，这是 MyBatis 提供的一个简单的、非线程安全的数据源实现。它主要用于演示和轻量级的用途，并不适合生产环境。
                    </p>
                </div>
            </div>

            <!-- Overview Section -->
            <div class="bg-white rounded-2xl shadow-xl p-8 mb-8 card-hover">
                <h2 class="section-title text-3xl font-bold text-gray-800">
                    1. UnpooledDataSource 概述
                </h2>
                
                <p class="text-gray-700 mb-6 leading-relaxed">
                    <code class="bg-purple-100 text-purple-800 px-2 py-1 rounded">UnpooledDataSource</code> 是 MyBatis 中的一个非池化数据源实现。它的主要特点是：
                </p>
                
                <div class="grid md:grid-cols-2 gap-6">
                    <div class="bg-gradient-to-br from-purple-50 to-pink-50 p-6 rounded-xl">
                        <div class="feature-icon icon-purple">
                            <i class="fas fa-link-slash"></i>
                        </div>
                        <h3 class="text-xl font-semibold mb-3 text-gray-800">非池化</h3>
                        <p class="text-gray-600">每次获取数据库连接时，都会创建一个新的连接，而不是从连接池中取出。这意味着没有连接复用。</p>
                    </div>
                    
                    <div class="bg-gradient-to-br from-blue-50 to-cyan-50 p-6 rounded-xl">
                        <div class="feature-icon icon-blue">
                            <i class="fas fa-cube"></i>
                        </div>
                        <h3 class="text-xl font-semibold mb-3 text-gray-800">简单实现</h3>
                        <p class="text-gray-600">它的实现非常简单，没有连接池管理的复杂逻辑，如连接池的创建、销毁、管理等。</p>
                    </div>
                </div>
            </div>

            <!-- Usage Scenarios -->
            <div class="bg-white rounded-2xl shadow-xl p-8 mb-8 card-hover">
                <h2 class="section-title text-3xl font-bold text-gray-800">
                    2. 使用场景
                </h2>
                
                <p class="text-gray-700 mb-6 leading-relaxed">
                    <code class="bg-purple-100 text-purple-800 px-2 py-1 rounded">UnpooledDataSource</code> 通常用于以下场景：
                </p>
                
                <div class="space-y-4">
                    <div class="flex items-start space-x-4 p-4 bg-gray-50 rounded-lg hover:bg-gray-100 transition-colors">
                        <div class="flex-shrink-0">
                            <div class="w-10 h-10 bg-gradient-to-br from-purple-500 to-pink-500 rounded-lg flex items-center justify-center text-white">
                                <i class="fas fa-flask"></i>
                            </div>
                        </div>
                        <div>
                            <h4 class="font-semibold text-gray-800 mb-1">开发和测试环境</h4>
                            <p class="text-gray-600">用于轻量级的开发和测试场景，便于快速配置和调试。</p>
                        </div>
                    </div>
                    
                    <div class="flex items-start space-x-4 p-4 bg-gray-50 rounded-lg hover:bg-gray-100 transition-colors">
                        <div class="flex-shrink-0">
                            <div class="w-10 h-10 bg-gradient-to-br from-blue-500 to-cyan-500 rounded-lg flex items-center justify-center text-white">
                                <i class="fas fa-chalkboard-teacher"></i>
                            </div>
                        </div>
                        <div>
                            <h4 class="font-semibold text-gray-800 mb-1">演示目的</h4>
                            <p class="text-gray-600">用于演示 MyBatis 的基本功能，不涉及性能和生产级的需求。</p>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Configuration -->
            <div class="bg-white rounded-2xl shadow-xl p-8 mb-8 card-hover">
                <h2 class="section-title text-3xl font-bold text-gray-800">
                    3. 如何配置
                </h2>
                
                <p class="text-gray-700 mb-6 leading-relaxed">
                    在 MyBatis 的配置文件中，你可以通过 <code class="bg-purple-100 text-purple-800 px-2 py-1 rounded">dataSource</code> 配置项指定使用 <code class="bg-purple-100 text-purple-800 px-2 py-1 rounded">UnpooledDataSource</code>。配置示例如下：
                </p>
                
                <div class="code-block">
                    <div class="code-header">
                        <div class="code-dots">
                            <span class="dot dot-red"></span>
                            <span class="dot dot-yellow"></span>
                            <span class="dot dot-green"></span>
                        </div>
                        <span>mybatis-config.xml</span>
                    </div>
                    <pre><code>&lt;configuration&gt;
  &lt;dataSource type="UNPOOLED"&gt;
    &lt;property name="driver" value="com.mysql.cj.jdbc.Driver"/&gt;
    &lt;property name="url" value="jdbc:mysql://localhost:3306/mydatabase"/&gt;
    &lt;property name="username" value="myuser"/&gt;
    &lt;property name="password" value="mypassword"/&gt;
  &lt;/dataSource&gt;

  &lt;!-- 其他配置 --&gt;
&lt;/configuration&gt;</code></pre>
                </div>
            </div>

            <!-- Comparison -->
            <div class="bg-white rounded-2xl shadow-xl p-8 mb-8 card-hover">
                <h2 class="section-title text-3xl font-bold text-gray-800">
                    4. 与其他连接池的比较
                </h2>
                
                <p class="text-gray-700 mb-6 leading-relaxed">
                    <code class="bg-purple-100 text-purple-800 px-2 py-1 rounded">UnpooledDataSource</code> 与其他流行的连接池（如 HikariCP、C3P0、Druid）相比，有以下几个显著的区别：
                </p>
                
                <div class="grid gap-6">
                    <div class="bg-gradient-to-r from-red-50 to-orange-50 p-6 rounded-xl border-l-4 border-red-400">
                        <div class="flex items-center mb-3">
                            <div class="feature-icon icon-orange mr-4" style="width: 40px; height: 40px; font-size: 18px;">
                                <i class="fas fa-tachometer-alt"></i>
                            </div>
                            <h3 class="text-xl font-semibold text-gray-800">性能</h3>
                        </div>
                        <p class="text-gray-600">由于没有连接池的特性，<code class="bg-orange-100 text-orange-800